<div style="margin:10px" class="div_form_content">
    <h1>Configuration management</h1>
    <table>
        <tr>
            <td>
                Configuration list | <a href="index.php?m=manage_configuration&a=create">Create new configuration</a>
            </td>
            <td>
                <div style="float:right; margin-right: 30px;">
                    
                    <span>Select configuration type: </span>
                    <select id="config_type">
                        <option value="0">- Select - </option>
                        <option value="1" <?=$sl=(($config_type==1)?'selected':'')?>> General CIs </option>
                        <option value="2" <?=$sl=(($config_type==2)?'selected':'')?>> Device CIs </option>
                    </select>
                    
                    <input type="text" id="search" value="<?=$s?>" />
                    <input type ="button" value="search" onclick="search()"/>
                </div>
            </td>
        </tr>

    </table>


<table >
   <tr>
       
       <th>Configuration name</th>
       <th>Description</th>
       <th>Device name</th>
       <th>Customer</th>
       <th>Time create</th>
       <th>Action</th>
   </tr>
    <?foreach($posts as $u):?>
   
   <tr >
       <td><a href="index.php?m=manage_configuration&a=view&c_id=<?=$u['idconfigurations']?>"><?=$u['configname']?></a></td>
       <td><?=$u['description']?></td>
       <td><?=$u['namedevice']?></td>
       <td><a href="index.php?m=manage_customer&a=view&c_id=<?=$u['idcustomer']?>"><?=$u['namecustomer']?> </a></td>
       <td><?=$u['starttime']?> </td>
       <td><a href="index.php?m=manage_configuration&a=edit&c_id=<?=$u['idconfigurations']?>">Edit</a> |<a href="javascript:deleteConfig(<?=$u['idconfigurations']?>)" >Delete</a></td>
   </tr>
   <?endforeach?>
</table>
    
    
    

<div id="page-number">
    <div id="page-number-left">
        Page 
        <?if($num_pages<=5):?> <!--11111so trang < 5 in tu 1 den 5-->
            <?for($i=1;$i<=$num_pages;$i++):?>
            <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
            <?endfor?>
        <?else:?>

            <?if($page_num<5):?> <!--222222222-so trang > 5  neu trang hienj tai <5 in tu 1 den 5-->
				
                <?for($i=1;$i<=5;$i++):?>
                <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                <?endfor?>
                <span style="border: 1px solid #eee; padding: 5px;">...</span>
                <span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="<?=$num_pages?>"><?=$num_pages?></span>

            <?else:?> <!--so trang > 5  neu trang hienj tai >= 5 phải kiểm tra lại num_pages-->
                <?if($num_pages>$page_num+4):?>
					<span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="1">1</span>
					<span style="border: 1px solid #eee; padding: 5px;">...</span>
                    <?for($i=$page_num-3;$i<=$page_num+3;$i++):?>
                    <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                    <?endfor?>
                    <span style="border: 1px solid #eee; padding: 5px;">...</span>
                    <span style="border: 1px solid #eee; padding: 5px;" class="span_page_number" title="<?=$num_pages?>"><?=$num_pages?></a></span>
                 <?else:?>
					<span style="border: 1px solid #ddd; padding: 5px;" class="span_page_number" title="1">1</span>
					<span style="border: 1px solid #ddd; padding: 5px;">...</span>
                    <?for($i=$page_num-3;$i<=$num_pages;$i++):?>
                    <span style="border: 1px solid #eee; padding: 5px;<?=$style=($i==$page_num)?'background-color: #ddd':'';?>" class="span_page_number" title="<?=$i?>"><?=$i?></span>
                    <?endfor?>
                  <?endif?>
            <?endif?> <!--222222222-so trang > 5  neu trang hienj tai <5 in tu 1 den 5-->
        <?endif?><!--11111so trang < 5 in tu 1 den 5-->

    </div>
</div>
</div>
<script>
function search(){
    var word=$('#search').val();
    var url="index.php?m=manage_configuration&a=index&s="+word;
    window.location=url;
}

function deleteCustomer(c_id){

    var conf = confirm("Are you sure you want to delete this customer?");
    if(conf == true){
         var url="index.php?m=manage_customer&a=delete&c_id="+c_id;
         window.location=url;
         //alert (url);
    }

}

$("#config_type").change(function(){
    var c_id=$("#config_type").val();
    var group= <?echo($group);?>;
    var word=$('#search').val();
    //alert(word);
    var url="index.php?m=manage_configuration&a=index";
    if(c_id!='0'){
        url=url+"&config_type="+c_id;
    }
    if(group!=""){
        url=url+"&group="+group;
    }
    if(word!=""){
        url=url+"&s="+word;
    }
    
    window.location=url;
});
</script>

<style>
    table{
        width: 100%;
        margin: 10px;
        
    }
td
{
padding:3px;
}
</style>

<script>
    
    $('span.span_page_number').on('click', function() {
    var page = $(this).attr("title"); 
    Refresh(page); 

});
function Refresh(p){

    var url="index.php?m=manage_customer&a=index&p="+p;  

    window.location=url;
}   
</script>
